#![allow(dead_code)]

use actix_web::{web, App, HttpRequest, HttpServer, Responder};

mod _enum;
mod aysnc1;
mod closure_capture_move;
mod closure_as_input;
mod _enum_linklist;
mod _struct;
mod debug;
mod display;
mod iter;
mod ownership;
mod slice;
mod tuple;

async fn greet(req: HttpRequest) -> impl Responder {
    let name = req.match_info().get("name").unwrap_or("World");
    format!("Hello {}!", &name)
}

#[actix_web::main]
async fn server() -> std::io::Result<()> {
    HttpServer::new(|| {
        App::new()
            .route("/", web::get().to(greet))
            .route("/{name}", web::get().to(greet))
    })
    .bind(("0.0.0.0", 18082))?
    .run()
    .await
}

fn main2() {
    iter::iter();
    // ownership
    ownership::ownership();
    println!("======> end ownership",);

    // debug
    debug::debug();
    println!("======> end debug",);

    // display
    display::display();
    println!("======> end display",);

    // tuple
    tuple::tuple();
    println!("======> end tuple",);

    // slice
    slice::slice();
    println!("======> end slice",);

    // _struct
    _struct::_struct();
    println!("======> end _struct",);

    // _enum
    _enum::_enum();
    println!("======> end _enum",);

    // _enum_linklist
    _enum_linklist::_enum_linklist();
    println!("======> end _enum_linklist",);

    // closure_capture_move
    closure_capture_move::closure_capture_move();
    println!("======> end closure_capture_move",);

    // closure_as_input
    closure_as_input::closure_as_input();
    println!("======> end closure_as_input",);

    // aysnc1
    aysnc1::aysnc1();
    println!("======> end aysnc1",);
}


fn main() {
    main2();
    println!("======> end main",);
    // let res = server();
    // println!("{:#?}",res)
}
